﻿using System;
using System.Data;
using System.Collections.Generic;
using SERP.DAO;
namespace SERP.Controllers
{
    public class PeopleController : PeopleControllerBase
    {
        public PeopleController()
            : base()
        {
        }
        private DataTable _Table;
        private PeopleEntity oPeople;
        public PeopleEntity PeopleObject
        {
            get
            {
                return oPeople;
            }
            set
            {
                oPeople = value;
            }
        }
        public DataTable Table
        {
            get
            {
                
                return _Table;
            }
            set
            {
                _Table = value;
            }
        }
        public void LoadAllDSPeople(List<int> lsOrganizationId)
        {
            string filter = "";
            if (lsOrganizationId.Count > 0)
            {
                filter = " OrganizationId IN(" + string.Join(",", lsOrganizationId.ConvertAll<string>(Convert.ToString).ToArray()) + ")";
            }
            else
            {
                filter = "0=1";
            }
            _Table = Service.SelectAllDSFilter(filter).Tables[0];
        }
        public void AddIndexToTable()
        {
            AddIndexToTable(_Table);
        }
        public void ResetTableIndex()
        {
            ResetTableIndex(_Table);
        }
        public void LoadObject(Int32 PersonId)
        {
            oPeople = Service.SelectOne(PersonId);

        }
        public bool AddNew()
        {
            if (oPeople == null) return false;
            bool result = Service.Save(oPeople);

            return result;
        }
        public bool Update()
        {
            if (oPeople == null) return false;
            return Service.Update(oPeople);
        }
        public bool Delete()
        {
            if (oPeople == null) return false;
            bool retvalue = Service.Delete(oPeople);

            return retvalue;
        }
        public bool DeleteByID(Int32 PersonId)
        {
            bool retvalue = Service.DeleteByID(PersonId);

            return retvalue;
        }
        public void ResetObject()
        {
            this.oPeople = new PeopleEntity();
        }
        public void MapObjectToDataRow(DataRow row)
        {
            this.MapObjectToDataRow(this.PeopleObject, row);
        }
        public PeopleEntity LoadPeople(Int32 PersonId)
        {
            PeopleEntity o = Service.SelectOne(PersonId);
            return o;
        }

    }
}
